//
//  ShopViewController.m
//  FaceTo
//
//  Created by chijia on 2017/6/18.
//  Copyright © 2017年 chengbangming. All rights reserved.
//

#import "ShopViewController.h"
#import "SDCycleScrollView.h"
#import "ShopIndexTableViewCell.h"
#import "ProductViewController.h"
@class ShopContent;
@interface ShopViewController ()<SDCycleScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
{
    NSMutableArray * BannerArray;
    NSMutableArray * dataArray;
    
}
@property (nonatomic ,strong)UITableView * tableView;
@property (nonatomic ,strong)ShopContent * model;

@end

@implementation ShopViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = WhiteColor;
    BannerArray = [[NSMutableArray alloc]init];
    dataArray = [[NSMutableArray alloc]init];
    
    self.title = @"商店";
    [self createData];
//    [self initUI];
    
}
- (void)createData{
    [CUseHttpTool getShopListSuccess:^(ShopModel *model) {
        if([model.code isEqualToString:@"200"]){
            dataArray = [model.content mutableCopy];
            [self initUI];
        }
    } failure:^(NSError *error) {
        if(error){
            [SVProgressHUD showErrorWithStatus:@"服务器繁忙"];
        }
    }];
}
- (void)initUI {
    
    
    //设置RightItem 的图片按钮
    UIButton* leftBtn= [UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setImage:[UIImage imageNamed:@"jilu"] forState:UIControlStateNormal];
    leftBtn.frame = CGRectMake(10, 0, 30, 30);
    UIBarButtonItem* leftBtnItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    [leftBtn addTarget:self action:@selector(rightItem) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = leftBtnItem;
    
    
    NSArray *imagesURLStrings = @[
                                  @"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg",
                                  @"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg",
                                  @"http://c.hiphotos.baidu.com/image/w%3D400/sign=c2318ff84334970a4773112fa5c8d1c0/b7fd5266d0160924c1fae5ccd60735fae7cd340d.jpg"
                                  ];
    SDCycleScrollView * cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_WIDTH/3*1.5) delegate:self placeholderImage:[UIImage imageNamed:@"chijia"]];
    cycleScrollView.currentPageDotImage = [UIImage imageNamed:@"pageControlCurrentDot"];
    cycleScrollView.pageDotImage = [UIImage imageNamed:@"pageControlDot"];
    cycleScrollView.imageURLStringsGroup = imagesURLStrings;
    cycleScrollView.autoScroll = NO;

    
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_HEIGHT-44) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
   
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREEN_WIDTH/3*1.5)];
    [headView addSubview:cycleScrollView];
    
     _tableView.tableHeaderView = headView;
    [self.view addSubview:_tableView];
    
    
}
- (void)rightItem {
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * identifier=@"cellIde";
    ShopIndexTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[ShopIndexTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    ShopContent * model = dataArray[indexPath.row];
    cell.model = model;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 125;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ProductViewController * vc = [[ProductViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    [self performSelector:@selector(unselectCell:) withObject:nil afterDelay:0.3];
}
- (void)unselectCell:(id)sender
{
    [_tableView deselectRowAtIndexPath:[_tableView indexPathForSelectedRow] animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
